package elitech.vietnam.copyweatherfashion.wsclient;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

import org.ksoap2.transport.HttpResponseException;
import org.xmlpull.v1.XmlPullParserException;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import elitech.vietnam.copyweatherfashion.entities.Comment;
import elitech.vietnam.copyweatherfashion.entities.Member;
import elitech.vietnam.copyweatherfashion.entities.Notify;
import elitech.vietnam.copyweatherfashion.entities.Post;
import elitech.vietnam.copyweatherfashion.entities.Product;
import elitech.vietnam.copyweatherfashion.entities.Store;
import elitech.vietnam.copyweatherfashion.utilities.Utilities;
import elitech.vietnam.copyweatherfashion.wsclient.Helper.Param;

public class Service {

	/**
	 * Get all posts by day index
	 * @param index
	 * @param country
	 * @param memID
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public ArrayList<Post> getFashionDay(int index, String country, int memID) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("index", index));
		params.add(new Param("country", country));
		params.add(new Param("memID", memID));
		
		String response = new Helper().sendRequest("GetFashionDayLike", params);
		
		Type type = new TypeToken<ArrayList<Post>>() {}.getType();

		ArrayList<Post> result = new Gson().fromJson(response, type);
		return result;
	}

	/**
	 * Get all posts by day index, limit by start & count
	 * @param index
	 * @param country
	 * @param memID
	 * @param start
	 * @param count
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public ArrayList<Post> getFashionDay(int index, String country, int memID, int start, int count) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("index", index));
		params.add(new Param("country", country));
		params.add(new Param("memID", memID));
		params.add(new Param("start", start));
		params.add(new Param("count", count));
		
		String response = new Helper().sendRequest("GetFashionDayLikePage", params);
		
		Type type = new TypeToken<ArrayList<Post>>() {}.getType();

		ArrayList<Post> result = new Gson().fromJson(response, type);
		return result;
	}
	
	/**
	 * Get styles all member by day, limit by start & count
	 * @param index
	 * @param country
	 * @param memID
	 * @param start
	 * @param count
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public ArrayList<Post> getFashionAllMemberDay(int index, String country, int memID, int start, int count) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("index", index));
		params.add(new Param("memID", memID));
		params.add(new Param("country", country));
		params.add(new Param("start", start));
		params.add(new Param("count", count));
		
		String response = new Helper().sendRequest("GetFashionDayAllMemberLikePage", params);
		
		Type type = new TypeToken<ArrayList<Post>>() {}.getType();

		ArrayList<Post> result = new Gson().fromJson(response, type);
		return result;
	}
	
	/**
	 * Get friends' styles by day, limit by start & count
	 * @param index
	 * @param country
	 * @param memID
	 * @param start
	 * @param count
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public ArrayList<Post> getFashionFriendDay(int index, String country, int memID, int start, int count) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("memID", memID));
		params.add(new Param("index", index));
		params.add(new Param("country", country));
		params.add(new Param("start", start));
		params.add(new Param("count", count));
		
		String response = new Helper().sendRequest("GetFashionDayFriendLikePage", params);
		
		Type type = new TypeToken<ArrayList<Post>>() {}.getType();

		ArrayList<Post> result = new Gson().fromJson(response, type);
		return result;
	}
	
	/**
	 * Get member's style limit by start & count
	 * @param memID
	 * @param myID
	 * @param country
	 * @param start
	 * @param count
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public ArrayList<Post> getFashionMember(int memID, int myID, String country, int start, int count) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("memID", memID));
		params.add(new Param("myID", myID));
		params.add(new Param("country", country));
		params.add(new Param("start", start));
		params.add(new Param("count", count));
		
		String response = new Helper().sendRequest("GetFashionMemberAndMyLikePage", params);
		
		Type type = new TypeToken<ArrayList<Post>>() {}.getType();

		ArrayList<Post> result = new Gson().fromJson(response, type);
		return result;
	}
	
	/**
	 * Get member's liked posts
	 * @param memID
	 * @param country
	 * @param start
	 * @param count
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public ArrayList<Post> getLikedPost(int memID, String country, int start, int count) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("memID", memID));
		params.add(new Param("country", country));
		params.add(new Param("start", start));
		params.add(new Param("count", count));
		
		String response = new Helper().sendRequest("GetPostLikeMember", params);
		
		Type type = new TypeToken<ArrayList<Post>>() {}.getType();

		ArrayList<Post> result = new Gson().fromJson(response, type);
		return result;
	}
	
	/**
	 * Like/unlike a post
	 * @param idmem
	 * @param idpost
	 * @param liked
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int newLike(int idmem, int idpost, int liked) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("idmem", idmem));
		params.add(new Param("idpost", idpost));
		params.add(new Param("liked", liked));
		
		String response = new Helper().sendRequest("NewLike", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Get list product of a post (store)
	 * @param idpost
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public ArrayList<Product> getListProduct(int idpost) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("idpost", idpost));
		
		String response = new Helper().sendRequest("GetListProduct", params);
		
		Type type = new TypeToken<ArrayList<Product>>() {}.getType();

		ArrayList<Product> result = new Gson().fromJson(response, type);
		return result;
	}
	
	/**
	 * Get store info by id
	 * @param idstore
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public Store getInfoStore(int idstore) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("idstore", idstore));

		String response = new Helper().sendRequest("GetInfoStore", params);

		Store result = new Gson().fromJson(response, Store.class);

		return result;
	}
	
	/**
	 * Get recent store posts by day
	 * @param idShop
	 * @param dayIndex
	 * @param countDay
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public ArrayList<Post> getThumbnailFashion(int idShop, String dayIndex, int countDay) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("idShop", idShop));
		params.add(new Param("dayIndex", dayIndex));
		params.add(new Param("countDay", countDay));
		
		String response = new Helper().sendRequest("GetThumbnailFashion", params);
		
		Type type = new TypeToken<ArrayList<Post>>() {}.getType();

		ArrayList<Post> result = new Gson().fromJson(response, type);
		return result;
	}
	
	/**
	 * Get post all member by page
	 * @param dayIndex
	 * @param memberId
	 * @param countryCode
	 * @param start
	 * @param count
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public ArrayList<Post> getFashionDayAllMemberLikePage(int dayIndex, int memberId, String countryCode, int start, int count) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("dayIndex", dayIndex));
		params.add(new Param("memberId", memberId));
		params.add(new Param("countryCode", countryCode));
		params.add(new Param("start", start));
		params.add(new Param("count", count));
		
		String response = new Helper().sendRequest("GetFashionDayAllMemberLikePage", params);
		
		Type type = new TypeToken<ArrayList<Post>>() {}.getType();

		ArrayList<Post> result = new Gson().fromJson(response, type);
		return result;
	}
	
	
	/**
	 * Get friend's posts by page
	 * @param dayIndex
	 * @param memberId
	 * @param countryCode
	 * @param start
	 * @param count
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public ArrayList<Post> getFashionDayFriendLikePage(int dayIndex, int memberId, String countryCode, int start, int count) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("memberId", memberId));
		params.add(new Param("dayIndex", dayIndex));
		params.add(new Param("countryCode", countryCode));
		params.add(new Param("start", start));
		params.add(new Param("count", count));
		
		String response = new Helper().sendRequest("GetFashionDayFriendLikePage", params);
		
		Type type = new TypeToken<ArrayList<Post>>() {}.getType();

		ArrayList<Post> result = new Gson().fromJson(response, type);
		return result;
	}
	
	/**
	 * Get member info by Id
	 * @param idmem
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public Member getInfoMemberById(int idmem, int idmine) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("idmem", idmem));
		params.add(new Param("idmine", idmine));

		String response = new Helper().sendRequest("GetInfoMemberById1", params);

		Member result = new Gson().fromJson(response, Member.class);

		return result;
	}
	
	/**
	 * Get list comment by post id limit start & count
	 * @param idpost
	 * @param start
	 * @param count
	 * @return
	 * @throws XmlPullParserException 
	 * @throws IOException 
	 * @throws HttpResponseException 
	 */
	public ArrayList<Comment> getListCommentPost(int idpost, int start, int count) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("idpost", idpost));
		params.add(new Param("start", start));
		params.add(new Param("count", count));
		
		String response = new Helper().sendRequest("GetListCommentPost", params);
		
		Type type = new TypeToken<ArrayList<Comment>>() {}.getType();

		ArrayList<Comment> result = new Gson().fromJson(response, type);
		return result;
	}
	
	/**
	 * Add friend to your friend list
	 * @param idmem
	 * @param idfriend
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int addFriend(int idmem, int idfriend) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("idmem", idmem));
		params.add(new Param("idfriend", idfriend));
		
		String response = new Helper().sendRequest("AddFriend", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Comment on a post
	 * @param idmem
	 * @param idpost
	 * @param content
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int newComment(int idmem, int idpost, String content) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("idmem", idmem));
		params.add(new Param("idpost", idpost));
		params.add(new Param("cmid", encodeString(idmem + " - " + idpost)));
		params.add(new Param("content", encodeString(content)));
		
		String response = new Helper().sendRequest("NewComment", params);
		
		return Integer.parseInt(response);
	}

	/**
	 * Login
	 * @param username
	 * @param password
	 * @param country
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int logIn(String username, String password, String country) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("username", encodeString(username)));
		params.add(new Param("password", encodeString(password)));
		params.add(new Param("country", encodeString(country)));
		
		String response = new Helper().sendRequest("Login", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Get post info by given ID
	 * @param idpost
	 * @param idmem
	 * @param country
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public Post getPostByID(int idpost, int idmem, String country) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<Param>();
		params.add(new Param("idpost", idpost));
		params.add(new Param("idmem", idmem));
		params.add(new Param("country", country));
		
		String response = new Helper().sendRequest("GetPostByID", params);

		Post result = new Gson().fromJson(response, Post.class);

		return result;
	}
	
	/**
	 * Get style of member limit by start & count
	 * @param idmem
	 * @param iduser
	 * @param country
	 * @param start
	 * @param count
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public ArrayList<Post> getMemberStylePage(int idmem, int iduser, String country, int start, int count) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<>();
		params.add(new Param("idmem", idmem));
		params.add(new Param("iduser", iduser));
		params.add(new Param("country", country));
		params.add(new Param("start", start));
		params.add(new Param("count", count));

		String response = new Helper().sendRequest("GetFashionMemberAndMyLikePage", params);
		
		Type type = new TypeToken<ArrayList<Post>>() {}.getType();

		ArrayList<Post> result = new Gson().fromJson(response, type);
		return result;
	}
	
	/**
	 * Get liked posts with limits
	 * @param idmem
	 * @param country
	 * @param start
	 * @param count
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public ArrayList<Post> getMemberLikedStylePage(int idmem, String country, int start, int count) throws HttpResponseException, IOException, XmlPullParserException {
		ArrayList<Param> params = new ArrayList<>();
		params.add(new Param("idmem", idmem));
		params.add(new Param("country", country));
		params.add(new Param("start", start));
		params.add(new Param("count", count));

		String response = new Helper().sendRequest("GetPostLikeMember", params);
		
		Type type = new TypeToken<ArrayList<Post>>() {}.getType();

		ArrayList<Post> result = new Gson().fromJson(response, type);
		return result;
	}
	
	/**
	 * Get list follower
	 * @param idmem
	 * @param start
	 * @param count
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public List<Member> getFollower(int idmem, int start, int count) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("idmem", idmem));
		params.add(new Param("start", start));
		params.add(new Param("count", count));

		String response = new Helper().sendRequest("GetFollower", params);
		
		Type type = new TypeToken<List<Member>>() {}.getType();

		List<Member> result = new Gson().fromJson(response, type);
		return result;
	}
	
	/**
	 * Get list following
	 * @param idmem
	 * @param start
	 * @param count
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public List<Member> getFollowing(int idmem, int start, int count) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("idmem", idmem));
		params.add(new Param("start", start));
		params.add(new Param("count", count));

		String response = new Helper().sendRequest("GetFollowing", params);
		
		Type type = new TypeToken<List<Member>>() {}.getType();

		List<Member> result = new Gson().fromJson(response, type);
		return result;
	}
	
	/**
	 * Follow a member
	 * @param idmem
	 * @param idfollow
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int follow(int idmem, int idfollow) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("idmem", idmem));
		params.add(new Param("idfollow", idfollow));
		
		String response = new Helper().sendRequest("Follow", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Unfollow a member
	 * @param idmem
	 * @param idfollow
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int unFollow(int idmem, int idfollow) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("idmem", idmem));
		params.add(new Param("idfollow", idfollow));
		
		String response = new Helper().sendRequest("Unfollow", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Update member information
	 * @param memid
	 * @param memname
	 * @param profile
	 * @param image
	 * @param coutry
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int updateUserInfo(String memid, String memname, String profile, String image, String country) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("memid", memid));
		params.add(new Param("memname", encodeString(memname)));
		params.add(new Param("profile", encodeString(profile)));
		params.add(new Param("image", encodeString(image)));
		params.add(new Param("country", country));
		
		String response = new Helper().sendRequest("UpdateUserInfo", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Change member's password
	 * @param idmem
	 * @param pass
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int changePassword(int idmem, String pass) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("idmem", idmem));
		params.add(new Param("pass", encodeString(Utilities.md5(pass))));
		
		String response = new Helper().sendRequest("ChangePassword", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Set notification read
	 * @param idnoti
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int readNotification(int idnoti) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("idnoti", idnoti));

		String response = new Helper().sendRequest("ReadNotification", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Get list notifications of user
	 * @param idmem
	 * @param start
	 * @param count
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public List<Notify> getNotifications(int idmem, int start, int count) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("idmem", idmem));
		params.add(new Param("start", start));
		params.add(new Param("count", count));

		String response = new Helper().sendRequest("GetNotifications", params);
		
		Type type = new TypeToken<List<Notify>>() {}.getType();

		List<Notify> result = new Gson().fromJson(response, type);
		return result;
		
	}
	
	/**
	 * App tracking
	 * @param iddevice
	 * @param appver
	 * @param api
	 * @param user
	 * @param day
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int appOpenTrack(String iddevice, String appver, int api, String user, String day) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("iddevice", encodeString(iddevice)));
		params.add(new Param("appver", appver));
		params.add(new Param("api", api));
		params.add(new Param("user", user));
		params.add(new Param("day", day));

		String response = new Helper().sendRequest("AppOpenTrack", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Store device and gcmid for tracking
	 * @param iddevice
	 * @param gcmid
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int newDeviceId(String iddevice, String gcmid) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("iddevice", encodeString(iddevice)));
		params.add(new Param("gcmid", encodeString(gcmid)));

		String response = new Helper().sendRequest("NewDevideID", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Update user's current Google Cloud Message ID
	 * @param memid
	 * @param gcmId
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int updateGCM(int memid, String gcmId) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("memid", memid));
		params.add(new Param("gcmId", encodeString(gcmId)));

		String response = new Helper().sendRequest("SetGCMID", params);
		
		return Integer.parseInt(response);
	}
	
	
	/**
	 * Sign up an account
	 * @param user
	 * @param pass
	 * @param name
	 * @param pic
	 * @param profile
	 * @param country
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int signUp(String user, String pass, String name, String pic, String profile, String country) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("user", encodeString(user)));
		params.add(new Param("pass", encodeString(Utilities.md5(pass))));
		params.add(new Param("name", encodeString(name)));
		params.add(new Param("pic", encodeString(pic)));
		params.add(new Param("profile", encodeString(profile)));
		params.add(new Param("country", country));
		
		String response = new Helper().sendRequest("CreateNewMember", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Create new post
	 * @param memId
	 * @param nam
	 * @param thang
	 * @param ngay
	 * @param title
	 * @param price
	 * @param link
	 * @param imageUrl
	 * @param content
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int createNewPost (int memId, int nam, int thang, int ngay, String title, String price, String link, String imageUrl, String content) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("memId", memId));
		params.add(new Param("nam", nam));
		params.add(new Param("thang", thang));
		params.add(new Param("ngay", ngay));
		params.add(new Param("title", encodeString(title)));
		params.add(new Param("price", encodeString(price)));
		params.add(new Param("link", encodeString(link)));
		params.add(new Param("imageUrl", imageUrl));
		params.add(new Param("content", encodeString(content)));
		
		String response = new Helper().sendRequest("CreateNewPost", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Update user's post
	 * @param memberId
	 * @param postId
	 * @param content
	 * @param pic
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int updatePost(int memberId, int postId, String content, String pic) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("memberId", memberId));
		params.add(new Param("postId", postId));
		params.add(new Param("pic", pic));
		params.add(new Param("content", encodeString(content)));
		
		String response = new Helper().sendRequest("UpdateFashionMember", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Delete user's post
	 * @param memid
	 * @param postid
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public int deletePost(int memid, int postid) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("memid", memid));
		params.add(new Param("postid", postid));
		
		String response = new Helper().sendRequest("DeleteFashionMember", params);
		
		return Integer.parseInt(response);
	}
	
	/**
	 * Send notification when comment successful
	 * @param idcomment
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public void notifyComment(int idcomment) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("idcomment", idcomment));
		
		new Helper().sendRequest("NotifyComment", params);
	}
	
	/**
	 * Send notification when a friend create post
	 * @param idpost
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public void notifyFriendPost(int idpost) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("idpost", idpost));
		
		new Helper().sendRequest("NotifyFriendPost", params);
	}
	
	/**
	 * Send notification when a friend added me
	 * @param idmem
	 * @param idfriend
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 */
	public void notifyFriendAdd(int idmem, int idfriend) throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		params.add(new Param("idmem", idmem));
		params.add(new Param("idfriend", idfriend));
		
		new Helper().sendRequest("NotifyFriendAdd", params);
	}
	
	/**
	 * Get current date from server
	 * @return
	 * @throws HttpResponseException
	 * @throws IOException
	 * @throws XmlPullParserException
	 * @throws ParseException
	 */
	public String getCurrentTime() throws HttpResponseException, IOException, XmlPullParserException {
		List<Param> params = new ArrayList<>();
		
		String response = new Helper().sendRequest("GetCurrentTime", params);
		
		return response;
	}
	
	
	
	
	private String encodeString(String string) {
		try {
			string = URLEncoder.encode(string, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return string;
	}

}
